<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of MynotificationController
 *
 * @author Admin
 */
class Street_MynotificationController extends Zend_Controller_Action{
    public function init() {
        /* Initialize action controller here */
    }

    public function preDispatch() {
        $auth = Zend_Auth::getInstance();
        if (!$auth->hasIdentity()) {
            $this->_redirect('/user/login');
        }

        $view = new Zend_View();
        $view->headTitle(' > Street Digging > Notifications');
        $this->view->userDetail = $auth->getIdentity();
    }
    
    public function indexAction(){
             
        $switchModel = new Application_Model_SwitchModel();

        $switches = $switchModel->getAllUserAssignedSwitchesForStreet($this->_request, $this->view->userDetail->id);

        $this->view->paginator = $switches;
    }
    public function filesAction(){
        $this->_helper->layout->disableLayout();
        $form = new Application_Form_documents_AddForm();
        $documentModel = new Application_Model_DocumentModel();
        $this->view->form = $form;
        $switchId = $this->_request->getParam('id');
        $cabinetId = $this->_request->getParam('page');
        if ($this->_request->isPost()) {

            $formData = $this->_request->getPost();
            if ($form->isValid($formData)) {
                $uploaded = move_uploaded_file($_FILES["doc_path"]["tmp_name"], "./uploads/files/" . $_FILES["doc_path"]["name"]);
                if ($uploaded) {
                    $data = array(
                        'name' => $this->_request->getPost('name'),
                        'file' => $_FILES["doc_path"]["name"],
                        'cabinet' => $this->_request->getPost('cabinet'),
                        'switch' => $this->_request->getPost('switch'),
                        'status' => 'active'
                    );                    
                    $documentModel->save($data);
                    $this->_redirect("street/mynotification");
                    exit;
                }
            }
        } else {
            $docs = $documentModel->getAllDocument('switch', $switchId);
            $this->view->files = $docs;
            $this->view->switchId = $switchId;
            $this->view->cabinetId = $cabinetId;
        }
    }
}